﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package org.aswing {
    import flash.events.*;
    import org.aswing.geom.*;
    import flash.text.*;
    import org.aswing.event.*;
    import org.aswing.plaf.basic.*;

    public class JTextArea extends JTextComponent implements Viewportable {

        public static const AUTO_INCREMENT:int = -2147483648;

        private static var defaultMaxChars:int = 0;

        private var columns:int;
        private var rows:int;
        private var viewPos:IntPoint;
        private var viewportSizeTesting:Boolean;
        private var lastMaxScrollV:int;
        private var lastMaxScrollH:int;
        private var verticalUnitIncrement:int;
        private var verticalBlockIncrement:int;
        private var horizontalUnitIncrement:int;
        private var horizontalBlockIncrement:int;
        private var focusScrolling:Boolean = false;

        public function JTextArea(_arg1:String="", _arg2:int=0, _arg3:int=0){
            setName("JTextField");
            getTextField().multiline = true;
            getTextField().text = _arg1;
            setMaxChars(defaultMaxChars);
            this.rows = _arg2;
            this.columns = _arg3;
            this.viewPos = new IntPoint();
            this.viewportSizeTesting = false;
            this.lastMaxScrollV = getTextField().maxScrollV;
            this.lastMaxScrollH = getTextField().maxScrollH;
            this.verticalUnitIncrement = AUTO_INCREMENT;
            this.verticalBlockIncrement = AUTO_INCREMENT;
            this.horizontalUnitIncrement = AUTO_INCREMENT;
            this.horizontalBlockIncrement = AUTO_INCREMENT;
            getTextField().addEventListener(Event.CHANGE, this.__onTextAreaTextChange);
            getTextField().addEventListener(Event.SCROLL, this.__onTextAreaTextScroll);
            this.updateUI();
        }
        public static function setDefaultMaxChars(_arg1:int):void{
            defaultMaxChars = _arg1;
        }
        public static function getDefaultMaxChars():int{
            return (defaultMaxChars);
        }

        override public function updateUI():void{
            setUI(UIManager.getUI(this));
        }
        override public function getDefaultBasicUIClass():Class{
            return (BasicTextAreaUI);
        }
        override public function getUIClassID():String{
            return ("TextAreaUI");
        }
        public function setColumns(_arg1:int):void{
            if (_arg1 < 0){
                _arg1 = 0;
            };
            if (this.columns != _arg1){
                this.columns = _arg1;
                if (isWordWrap()){
                };
                revalidate();
            };
        }
        public function getColumns():int{
            return (this.columns);
        }
        public function setRows(_arg1:int):void{
            if (_arg1 < 0){
                _arg1 = 0;
            };
            if (this.rows != _arg1){
                this.rows = _arg1;
                if (isWordWrap()){
                };
                revalidate();
            };
        }
        public function getRows():int{
            return (this.rows);
        }
        override protected function isAutoSize():Boolean{
            return ((((this.columns == 0)) || ((this.rows == 0))));
        }
        override protected function countPreferredSize():IntDimension{
            var _local1:IntDimension;
            var _local2:int;
            var _local3:int;
            var _local4:int;
            var _local5:int;
            if ((((this.columns > 0)) && ((this.rows > 0)))){
                _local2 = ((getColumnWidth() * this.columns) + getWidthMargin());
                _local3 = ((getRowHeight() * this.rows) + getHeightMargin());
                _local1 = new IntDimension(_local2, _local3);
            } else {
                if ((((this.rows <= 0)) && ((this.columns <= 0)))){
                    _local1 = getTextFieldAutoSizedSize();
                } else {
                    if (this.rows > 0){
                        _local4 = ((getRowHeight() * this.rows) + getHeightMargin());
                        _local1 = getTextFieldAutoSizedSize(0, _local4);
                    } else {
                        _local5 = ((getColumnWidth() * this.columns) + getWidthMargin());
                        _local1 = getTextFieldAutoSizedSize(_local5, 0);
                    };
                };
            };
            return (getInsets().getOutsideSize(_local1));
        }
        protected function fireStateChanged(_arg1:Boolean=true):void{
            dispatchEvent(new InteractiveEvent(InteractiveEvent.STATE_CHANGED, _arg1));
        }
        override protected function size():void{
            super.size();
            applyBoundsToText(getPaintBounds());
        }
        private function __onTextAreaTextChange(_arg1:Event):void{
            if (this.viewportSizeTesting){
                return;
            };
        }
        private function __onTextAreaTextScroll(_arg1:Event):void{
            var _local4:IntPoint;
            if (this.viewportSizeTesting){
                return;
            };
            var _local2:TextField = getTextField();
            if (this.focusScrolling){
                _local4 = this.getViewPosition();
                _local2.scrollH = _local4.x;
                _local2.scrollV = (_local4.y + 1);
                return;
            };
            var _local3:IntPoint = new IntPoint(_local2.scrollH, (_local2.scrollV - 1));
            if (!this.getViewPosition().equals(_local3)){
                this.viewPos.setLocation(_local3);
                this.fireStateChanged(true);
            };
            if (((!((this.lastMaxScrollV == _local2.maxScrollV))) || (!((this.lastMaxScrollH == _local2.maxScrollH))))){
                this.lastMaxScrollV = _local2.maxScrollV;
                this.lastMaxScrollH = _local2.maxScrollH;
                revalidate();
            };
        }
        override public function makeFocus():void{
            if (getFocusTransmit() == null){
                this.focusScrolling = true;
                super.makeFocus();
                this.focusScrolling = false;
            };
        }
        public function addStateListener(_arg1:Function, _arg2:int=0, _arg3:Boolean=false):void{
            addEventListener(InteractiveEvent.STATE_CHANGED, _arg1, false, _arg2);
        }
        public function removeStateListener(_arg1:Function):void{
            removeEventListener(InteractiveEvent.STATE_CHANGED, _arg1);
        }
        public function getVerticalUnitIncrement():int{
            if (this.verticalUnitIncrement == AUTO_INCREMENT){
                return (1);
            };
            return (this.verticalUnitIncrement);
        }
        public function getVerticalBlockIncrement():int{
            if (this.verticalBlockIncrement == AUTO_INCREMENT){
                return (10);
            };
            return (this.verticalBlockIncrement);
        }
        public function getHorizontalUnitIncrement():int{
            if (this.horizontalUnitIncrement == AUTO_INCREMENT){
                return (getColumnWidth());
            };
            return (this.horizontalUnitIncrement);
        }
        public function getHorizontalBlockIncrement():int{
            if (this.horizontalBlockIncrement == AUTO_INCREMENT){
                return ((getColumnWidth() * 10));
            };
            return (this.horizontalBlockIncrement);
        }
        public function setVerticalUnitIncrement(_arg1:int):void{
            if (this.verticalUnitIncrement != _arg1){
                this.verticalUnitIncrement = _arg1;
                this.fireStateChanged();
            };
        }
        public function setVerticalBlockIncrement(_arg1:int):void{
            if (this.verticalBlockIncrement != _arg1){
                this.verticalBlockIncrement = _arg1;
                this.fireStateChanged();
            };
        }
        public function setHorizontalUnitIncrement(_arg1:int):void{
            if (this.horizontalUnitIncrement != _arg1){
                this.horizontalUnitIncrement = _arg1;
                this.fireStateChanged();
            };
        }
        public function setHorizontalBlockIncrement(_arg1:int):void{
            if (this.horizontalBlockIncrement != _arg1){
                this.horizontalBlockIncrement = _arg1;
                this.fireStateChanged();
            };
        }
        public function scrollToBottomLeft():void{
            this.setViewPosition(new IntPoint(0, int.MAX_VALUE));
        }
        public function scrollToBottomRight():void{
            this.setViewPosition(new IntPoint(int.MAX_VALUE, int.MAX_VALUE));
        }
        public function scrollToTopLeft():void{
            this.setViewPosition(new IntPoint(0, 0));
        }
        public function scrollToTopRight():void{
            this.setViewPosition(new IntPoint(int.MAX_VALUE, 0));
        }
        public function scrollRectToVisible(_arg1:IntRectangle, _arg2:Boolean=true):void{
            this.setViewPosition(new IntPoint(_arg1.x, _arg1.y), _arg2);
        }
        public function setViewPosition(_arg1:IntPoint, _arg2:Boolean=true):void{
            if (!this.viewPos.equals(_arg1)){
                this.restrictionViewPos(_arg1);
                if (this.viewPos.equals(_arg1)){
                    return;
                };
                this.viewPos.setLocation(_arg1);
                this.validateScroll();
                this.fireStateChanged(_arg2);
            };
        }
        public function setViewportTestSize(_arg1:IntDimension):void{
            this.viewportSizeTesting = true;
            setSize(_arg1);
            this.validateScroll();
            this.viewportSizeTesting = false;
        }
        public function getViewSize():IntDimension{
            var _local2:int;
            var _local3:int;
            var _local1:TextField = getTextField();
            if (isWordWrap()){
                _local2 = _local1.textWidth;
                _local1.scrollH = 0;
            } else {
                if (_local1.maxScrollH > 0){
                    _local2 = (_local1.textWidth + _local1.maxScrollH);
                } else {
                    _local2 = _local1.textWidth;
                    _local1.scrollH = 0;
                };
            };
            var _local4:int = ((_local1.bottomScrollV - _local1.scrollV) + 1);
            var _local5:int = (_local1.maxScrollV + _local4);
            var _local6 = 1;
            _local3 = (_local5 - _local6);
            return (new IntDimension(_local2, _local3));
        }
        public function getExtentSize():IntDimension{
            var _local1:TextField = getTextField();
            var _local2:int = ((_local1.bottomScrollV - _local1.scrollV) + 1);
            var _local3:int = _local1.textWidth;
            return (new IntDimension(_local3, _local2));
        }
        public function getViewportPane():Component{
            return (this);
        }
        public function getViewPosition():IntPoint{
            return (this.viewPos.clone());
        }
        protected function validateScroll():void{
            var _local1:int = this.viewPos.x;
            var _local2:int = (this.viewPos.y + 1);
            var _local3:TextField = getTextField();
            if (_local3.scrollH != _local1){
                _local3.scrollH = _local1;
            };
            if (_local3.scrollV != _local2){
                _local3.scrollV = _local2;
            };
        }
        protected function restrictionViewPos(_arg1:IntPoint):IntPoint{
            var _local2:IntPoint = this.getViewMaxPos();
            _arg1.x = Math.max(0, Math.min(_local2.x, _arg1.x));
            _arg1.y = Math.max(0, Math.min(_local2.y, _arg1.y));
            return (_arg1);
        }
        private function getViewMaxPos():IntPoint{
            var _local1:IntDimension = this.getExtentSize();
            var _local2:IntDimension = this.getViewSize();
            var _local3:IntPoint = new IntPoint((_local2.width - _local1.width), (_local2.height - _local1.height));
            if (_local3.x < 0){
                _local3.x = 0;
            };
            if (_local3.y < 0){
                _local3.y = 0;
            };
            return (_local3);
        }

    }
}//package org.aswing 
